package com.whmnx.my.ui.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.whmnx.base.bean.MyBagListBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.my.BR;
import com.whmnx.my.R;
import com.whmnx.my.databinding.FragmentBodou2Binding;
import com.whmnx.my.ui.adapter.BodouListAdapter;
import com.whmnx.my.ui.fragment.BodouFragment2;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 * author : huang
 * date   : 2020/9/29 0029 10:55
 * version: 1.0
 * @author Administrator
 */
public class Bodou2Model extends BaseViewModel {
    public BodouFragment2 mFragment;
    FragmentBodou2Binding mBinding;
    private BodouListAdapter pingJiaListAdapter;

    public Bodou2Model(@NonNull Application application) {
        super(application);
    }


    public void initToolbar(BodouFragment2 bodouFragment, FragmentBodou2Binding binding) {
        this.mFragment = bodouFragment;
        this.mBinding = binding;
        LinearLayoutManager layoutManager = new LinearLayoutManager(mFragment.getActivity());
        //配置布局，默认为vertical（垂直布局），下边这句将布局改为水平布局
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mBinding.rvGoodsList.setLayoutManager(layoutManager);
        mBinding.rvGoodsList.setItemAnimator(new DefaultItemAnimator());

        pingJiaListAdapter = new BodouListAdapter(mFragment.getActivity());
        mBinding.rvGoodsList.setAdapter(pingJiaListAdapter);

        getBeanBagList();
    }

    private void getBeanBagList() {
        Map<String, Object> params = new HashMap<>();
        params.put("uId", SPUtils.getInstance().getString(Constants.USERID));
        params.put("status", 0);
        params.put("pageIndex", 1);
        params.put("pageSize", 10);
        HttpClient.post(mFragment.getActivity(), Constants.BEANBAGLIST, params,new CallBack<List<MyBagListBean>>() {
            @Override
            public void onSuccess(List<MyBagListBean> bagListBeans) {
                pingJiaListAdapter.replaceAll(bagListBeans,true);
            }
        });
    }



    //给RecyclerView添加ObservableList
    public ObservableList<BodouItemViewModel2> observableList = new ObservableArrayList<>();
    //给RecyclerView添加ItemBinding

    public ItemBinding<BodouItemViewModel2> itemBinding = ItemBinding.of(BR.viewModel, R.layout.my_item_bodou2);




}
